#include "CloudControlPointCmd.h"

CloudControlPointCmd::CloudControlPointCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::CloudProtocol;
    this->m_functionCode = FunctionCode;
    m_address = 0;
    m_value=0;
}


Package CloudControlPointCmd::toPackage()
{
    Package package;
    QByteArray body;

    body.append(DataTypeConver::intToByteArray(m_address,2));
    body.append(DataTypeConver::intToByteArray(m_value,2));

 //   body = encrypt(body,KeyType::AES);

    package.setId(m_cmdId);
    package.setFunction(FunctionCode);
    package.setBody(body);
    return package;
}

void CloudControlPointCmd::unPackage(Package package)
{
    m_cmdId = package.id();
    QByteArray body=package.body();

    qDebug()<<"CloudControlPointCmd unPackage:";
    QString str;
    for(int i=0;i<body.size();i++)
    {
        str+=QString("%1").arg((unsigned char)body.at(i),2,16,QLatin1Char('0'))+' ';
    }
    qDebug()<<"print data::"<<str;  //打印十六进制数据


  //  body = decrypt(package.body(),KeyType::AES);
    m_address = body.mid(0,2).toHex().toInt(0,16);
    m_value = body.mid(2,2).toHex().toInt(0,16);

}


quint16 CloudControlPointCmd::address() const
{
    return m_address;
}

void CloudControlPointCmd::setAddress(const quint16 &address)
{
    m_address = address;
}
quint16 CloudControlPointCmd::value() const
{
    return m_value;
}

void CloudControlPointCmd::setValue(const quint16 &value)
{
    m_value = value;
}

